####################################################################################
#Figure D2: Distribution of $\rho_1$ and $\rho_2$ in Skill Specific, Offshore, RTI
#Author: Raluca L. Pahontu
####################################################################################

data <- read.dta13("shp_ss_off.dta")

#skillspecific
tab.ss <- table(data$skill_specificity, data$rho)
df.ss <- as.data.frame(prop.table(tab.ss, 2) )
df.ss <- df.ss[27:78,]
ss <- ggplot(df.ss, aes(fill=Var2, y=Freq, x=Var1)) + 
  geom_bar( stat="identity", width=0.99, colour="grey60") +
  scale_fill_manual(values=alpha(c("black", "grey60"), 0.2), name="Work Type", labels=c("rho2", "rho1")) + theme_bw() +
  theme(axis.text.x = element_blank(), axis.ticks.x = element_blank()) + xlab("Skill Specificity (Ascending Order)") + ylab("Frequencies") 


#offshore
tab.off <- table(data$offshore1, data$rho)
df.off <- as.data.frame(prop.table(tab.off, 2) )
df.off <- df.off[22:63,]
off <- ggplot(df.off, aes(fill=Var2, y=Freq, x=Var1)) + 
  geom_bar( stat="identity",  width=0.99, colour="grey60") +
  scale_fill_manual(values=alpha(c("black", "grey60"), 0.2), name="Work Type", labels=c("rho2", "rho1")) + theme_bw() +
  theme(axis.text.x = element_blank(), axis.ticks.x = element_blank()) + xlab("Offshoring (Ascending Order)") + 
  ylab(" ")


#rti

tab.rti <- table(data$rti, data$rho)
df.rti <- as.data.frame(prop.table(tab.rti, 2) )
df.rti <- df.rti[22:63,]
rti <- ggplot(df.rti, aes(fill=Var2, y=Freq, x=Var1)) + 
  geom_bar( stat="identity",  width=0.99, colour="grey60") +
  scale_fill_manual(values=alpha(c("black", "grey60"), 0.2), name="Work Type", labels=c("rho2", "rho1")) + theme_bw() +
  theme(axis.text.x = element_blank(), axis.ticks.x = element_blank()) + xlab("RTI (Ascending Order)") + 
  ylab(" ")

ggarrange(ss,off,rti, common.legend = T, ncol=3, legend = "bottom")
ggsave(file="fig_d2.pdf")



